package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.PushConfigStockService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.PushConfigStockDto;
import com.huilian.iotbox.data.enums.RoleEnum;
import com.huilian.iotbox.data.vo.UserInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author LinYinDong
 * @date 2024/7/23 下午6:19
 */
@RestController
@RequestMapping("/api/pushConfigStock")
public class PushConfigStockController extends UserInfoController {
    @Resource
    private PushConfigStockService pushConfigStockService;

    @PostMapping("/findPushConfigStockDeviceNo")
    public ServerResponse findPushConfigStockDeviceNo(HttpServletRequest request, @RequestBody PushConfigStockDto pushConfigStockDto) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        pushConfigStockDto.setUserInfo(userInfo);
        return pushConfigStockService.findPushConfigStockDeviceNo(pushConfigStockDto);
    }

    @PostMapping("/editPushConfigStockItem")
    public ServerResponse editPushConfigStock(HttpServletRequest request, @RequestBody PushConfigStockDto pushConfigStockDto) {
        UserInfo userInfo = super.getLoginUserInfo(request);
        pushConfigStockDto.setUserInfo(userInfo);
        if (RoleEnum.SUB_ACCOUNT.getRoleId().equals(userInfo.getRoleId())) {
            pushConfigStockDto.setUserId(userInfo.getParentId());
        } else {
            pushConfigStockDto.setUserId(userInfo.getId());
        }
        return pushConfigStockService.editPushConfigStock(pushConfigStockDto);
    }
}
